/*
 * File name: BasePlugin.java
 *
 * Description: TODO
 *
 * Author: Theobald_Wu, contact with wuqizhi@tydtech.com
 *
 * Date: May 27, 2015  4:49:30 PM
 *
 * Copyright (C) 2015 Zhouyou Network Technology Co.,Ltd.
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.freeme.pluginmanager;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

public class BasePlugin extends Activity {
    private static final String TAG = "[FREEME_DBG]BasePlugin";
    protected Context mHostContext;
    protected Context mContext;

    public BasePlugin() {
        super();
    }

    /**
     * Construct function
     *
     * @param context
     * @param packageName package context need create (getPackageName() would
     *            throw null pointer exception), so must import package name.
     */
    public BasePlugin(Context context, String packageName) {
        mHostContext = context;

        try {
            Log.i(TAG, "construct: packageName = " + packageName);
            mContext = mHostContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE
                    | Context.CONTEXT_IGNORE_SECURITY);
        } catch (NameNotFoundException e) {
            mContext = mHostContext;
        }
    }

    /**
     * @Title: getContext
     * @Description: get context of plugin
     * @param:
     * @return: Context
     */
    public Context getContext() {
        return mContext;
    }

    public void notifyOrientationChanged(int ori) {
        onOrientationChanged(ori);
    }

    public void release() {
        // release resources
        onRelease();
    }

    protected void onOrientationChanged(int orientation) {
    }

    protected void onRelease() {
    }
}
